package krt.wid.gslzs.util;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;

/**
 * @author Marcus
 * @package krt.wid.tour_gz.krt.wid.gslzs.util
 * @description
 * @time 2016/12/24
 * Glide配置工具库
 */

public class GlideUtil {
    /**
     * 正常加载
     *
     * @param context
     * @param o
     * @param imageView
     */
    public static void load(Context context, Object o, ImageView imageView) {
        Glide.with(context).load(o).listener(new RequestListener<Object, GlideDrawable>() {
            @Override
            public boolean onException(Exception e, Object o, Target<GlideDrawable> target, boolean b) {

                return false;
            }

            @Override
            public boolean onResourceReady(GlideDrawable glideDrawable, Object o, Target<GlideDrawable> target, boolean b, boolean b1) {
                return false;
            }
        }).into(imageView);
    }

    /**
     * 带crossFade动画加载
     */
    public static void loadWithAnim(Context context, Object o, ImageView imageView) {
        Glide.with(context).load(o).into(imageView);
    }

    /**
     * 加载gif动画
     *
     * @param mContext
     * @param path
     * @param mImageView
     */
    public static void loadGif(Context mContext, String path, ImageView mImageView) {
        Glide.with(mContext).load(path).asGif().into(mImageView);
    }

    /**
     * 带占位符的加载
     */
    public static void loadWithPlaceHolder(Context mContext, Object o, int placeHolder, ImageView imageView) {
        Glide.with(mContext).load(o).placeholder(placeHolder).into(imageView);
    }

    /**
     * 设置失败的图片
     */
    public static void loadWithError(Context mContext, Object o, int placeHolder, int error, ImageView imageView) {
        Glide.with(mContext).load(o).placeholder(placeHolder).error(error).into(imageView);
    }
    /**
     * 设置失败的图片
     */
    public static void loadWithError(Context mContext, Object o, int error, ImageView imageView) {
        Glide.with(mContext).load(o).error(error).into(imageView);
    }

    /**
     * 设置缓存
     */
    public static void loadWithMemory(Context mContext, Object o, int placeHolder, ImageView imageView) {
        Glide.with(mContext).load(o).placeholder(placeHolder).skipMemoryCache(true).into(imageView);
    }





    /**
     * 停止使用Glide加载图片
     */
    public static void stopLoad(Context context) {
        Glide.with(context).pauseRequests();
    }

    /**
     * 回复使用Glide加载图片
     */
    public static void resumeLoad(Context context) {
        Glide.with(context).resumeRequests();
    }





}
